package org.darcy.youchat.library.emoji;


import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class EmojiAdapter extends BaseAdapter {

    private Context mContext;
    private int mStartIndex;

    public EmojiAdapter(Context mContext, int startIndex) {
        this.mContext = mContext;
        this.mStartIndex = startIndex;
    }

    public int getCount() {
        int count = EmojiManager.getDisplayCount() - this.mStartIndex + 1;
        count = Math.min(count, 28);
        return count;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return mStartIndex + position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.nim_emoji_item, null);
        ImageView emojiThumb = (ImageView) convertView.findViewById(R.id.imgEmoji);
        int count = EmojiManager.getDisplayCount();
        int index = mStartIndex + position;
        if (position == 27 || index == count) {
            emojiThumb.setBackgroundResource(R.drawable.nim_emoji_del);
        } else if (index < count) {
            emojiThumb.setBackgroundDrawable(EmojiManager.getDisplayDrawable(mContext, index));
        }
        return convertView;
    }

}
